#pragma once

#include <stdlib.h>
#include <crtdbg.h>
#include <iostream>
using namespace std;
#define _CRTDBG_MAP_ALLOC

// -----------------------------------------------------
//  Memory Leak Checker
// -----------------------------------------------------
// - Call Constructor at the start before anything else in "main" function.
// - Will dump memory leaks only while debugging.

class CMemoryLeakChecker
{
public:
	// Constructor
	CMemoryLeakChecker(void)
	{
		// Flag Type Of Leaks To Check For
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	}

	// Constructor ( Break At Block Allocation )
	CMemoryLeakChecker(long BlockAllocation)
	{
		// Flag Type Of Leaks To Check For
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

		// Set Block ALlocation
		_CrtSetBreakAlloc( BlockAllocation );
	}

	// Destructor
	~CMemoryLeakChecker(void)
	{
		// Dump Leaks
		_CrtDumpMemoryLeaks();
	}
};
